-- 左侧边栏 文件管理配置

local status, nvim_tree = pcall(require, "nvim-tree")
if not status then
    vim.notify("没有找到nvim-tree")
  return
end

-- map <Space>n to toggle NvimTree
-- 这个是打开 NvimTree 的快捷键，我根据个人习惯使用了 Space + t
vim.api.nvim_set_keymap("n", "<Space>t", "::NvimTreeToggle<CR>", { noremap = true, silent = true })

-- 自动关闭
vim.cmd([[
  autocmd BufEnter * ++nested if winnr('$') == 1 && bufname() == 'NvimTree_' . tabpagenr() | quit | endif
]])

--nvim-tree配置
nvim_tree.setup({
	sort_by = "case_sensitive",
  --auto_close = true,
  auto_reload_on_write = false,
  disable_netrw = false,
  hijack_cursor = false,
  hijack_netrw = true,
  hijack_unnamed_buffer_when_opening = false,
  -- ignore_buffer_on_setup = false,
  -- open_on_setup = false,
  -- open_on_setup_file = false,
  open_on_tab = false,
  --root_dir = {},
  prefer_startup_root = false,
  sync_root_with_cwd = true,
  reload_on_bufenter = false,
  respect_buf_cwd = false,
  on_attach = "default",
  select_prompts = false,

  --update_cwd = false,

	-- 显示 git 状态图标(切换时会有延迟，比较慢)
	git = {
    enable = false,
    show_on_dirs = true,
    show_on_open_dirs = true,
    disable_for_dirs = {},
    timeout = 400,
    cygwin_support = false,
	},
	
  -- project plugin 需要这样设置
	-- update_cwd = true,
	-- update_focused_file = {
	-- 	enable = true,
	-- 	update_cwd = true,
	-- },

	-- 隐藏 .文件 和 node_modules 文件夹
	filters = {
    enable = true,
		dotfiles = false,
		custom = { "node_modules", ".git", "\\.cache" },
    git_clean = false,
    git_ignored = false,
    no_bookmark = false,
    no_buffer = false,
    exclude = {},
	},
	view = {
		-- 宽度
		width = 30,
		-- 也可以 'right'
		side = "left",
		-- 不显示行数
		number = false,
		relativenumber = false,
		-- 显示图标
		signcolumn = "yes",
    adaptive_size = false,
    centralize_selection = true,
    cursorline = true,
    debounce_delay = 15,
    preserve_window_proportions = false,
    float = {
      enable = false,
      quit_on_focus_loss = true,
      open_win_config = {
        relative = "editor",
        border = "rounded",
        width = 30,
        height = 30,
        row = 1,
        col = 1,
      },
    },
  },
	renderer = {
		--root_folder_label = true,
    -- highlight_git = true,
    add_trailing = false,
    group_empty = false,
    highlight_git = "name",
    highlight_opened_files = "none",
    root_folder_label = ":t",
    full_name = false,
    indent_width = 2,
    special_files = { "Cargo.toml", "Makefile", "README.md", "readme.md" },
    symlink_destination = true,
    highlight_diagnostics = "none",
    highlight_modified = "none",
    highlight_bookmarks = "none",
    highlight_clipboard = "name",
    indent_markers = {
      enable = false,
      inline_arrows = true,
      icons = {
        corner = "└",
        edge = "│",
        item = "│",
        bottom = "─",
        none = " ",
      },
    },
		-- group_empty = true,
		icons = {
      webdev_colors = true,
      git_placement = 'before',
      padding = ' ',
      symlink_arrow = ' ➛ ',
      modified_placement = "after",
      diagnostics_placement = "signcolumn",
      bookmarks_placement = "signcolumn",
			show = {
				git = true,
				file = true,
				folder = true,
				folder_arrow = true,
			},
			glyphs = {
				bookmark = " ",
				folder = {
					arrow_closed = "⏵",
					arrow_open = "⏷",
				},
				git = {
					unstaged = "✗",
					staged = "✓",
					unmerged = "⌥",
					renamed = "➜",
					untracked = "★",
					deleted = "⊖",
					ignored = "◌",
				},
			},
		},
  },
  filesystem_watchers = {
    enable = true,
    debounce_delay = 50,
    ignore_dirs = {},
  },		
	actions = {
    use_system_clipboard = true,
		open_file = {
			-- 首次打开大小适配
			resize_window = true,
			-- 打开文件时关闭
			quit_on_open = false,
		},
	},
})
